class Solution {
    public int longestOnes(int[] nums, int k) {
        int n=nums.length;
        int zero=0;
        int len=0;
        for(int right=0,left=0;right<n;right++ ){
            if(nums[right]==0){
                zero++;//进窗口
            }
            while(zero>k){//判断条件
                if(nums[left++]==0){
                    zero--;//出窗口
                }

            }
            len=Math.max((right-left)+1,len);

        }

        return len;
    }
}


public class demo9 {
    public static void main(String[] args) {
        int[] num={0,0,0,1};
        int k=4;
        Solution solution=new Solution();
        int a=solution.longestOnes(num,k);
        System.out.println(a);
    }
}
